const TokenKey = 'token'
const StateKey = 'state'
const loginInfoKey = 'loginInfo'

/**
 *  获取用户状态
 */
export function getStateSync() {
	return uni.getStorageSync(StateKey);
}

/**
 *  获取用户登录信息
 */
export function getLoginInfoSync() {
	return uni.getStorageSync(loginInfoKey);
}

/**
 * 本地存储用户状态
 */
export function setStateSync(state) {
	console.log(JSON.stringify(state))
	return uni.setStorageSync(StateKey, JSON.stringify(state));
}
/**
 * 本地存储登录信息
 */
export function setLoginInfoSync(info) {
	return uni.setStorageSync(loginInfoKey, JSON.stringify(info));
}

/**
 * 异步删除状态
 */
export function removeState() {
	return uni.removeStorage({
		key: StateKey,
		success: function(res) {
			console.log('删除State success');
			console.log(res.data);
		}
	});
}

/**
 * 删除状态
 */
export function removeStateSync() {
	return uni.removeStorageSync(StateKey)	
}

/**
 * 删除状态
 */
export function removeLoginInfoSync() {
	return uni.removeStorageSync(loginInfoKey)	
}


/**
 * 异步
 */
export function getToken() {
	return uni.getStorage({
		key: TokenKey,
		success: function(res) {
		}
	});
}

export function setToken(token) {
	return uni.setStorage({
		key: TokenKey,
		data: token,
		success: function(res) {
			console.log("success")
		}
	});
}

export function removeToken() {
	return uni.removeStorage({
		key: TokenKey,
		success: function(res) {
			console.log('删除Tokensuccess');
			console.log(res.data);
		}
	});
}

/**
 * 同步
 */
export function getTokenSync() {
	return uni.getStorageSync(TokenKey);
}

export function setTokenSync(token) {
	return uni.setStorageSync(TokenKey, token);
}

export function removeTokenSync() {
	return uni.removeStorageSync(TokenKey);
}
